package com.tvunetworks.center.user.config.web;

import com.tvunetworks.center.user.interceptor.AccessAppInterceptor;
import com.tvunetworks.center.user.resolver.LoginedNullableArgumentResolver;
import com.tvunetworks.center.user.service.UserService;
import com.tvunetworks.center.user.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import java.util.List;

/**
 * @program:
 * @description:
 * @author HenryChen
 * @create: 10/17/2019 6:09 PM
 **/
@Configuration
public class WebConfiguration extends WebMvcConfigurationSupport {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    @Lazy
    private UserService userService;

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
        super.addArgumentResolvers(argumentResolvers);
        argumentResolvers.add(new LoginedNullableArgumentResolver(redisUtil,userService));
    }

    @Bean
    public AccessAppInterceptor getAccessAppInterceptor() {
        return new AccessAppInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getAccessAppInterceptor());
        super.addInterceptors(registry);
    }
}
